// 提供工具函数

// menulist 完整展示列表
let menulist = [
    {
        label: "就业升学信息",
        icon: "el-icon-platform-eleme",
        id: 1,
        isshow: false,
        children: [
            {
                id: 11,
                label: "就业升学表格",
                icon: "el-icon-c-scale-to-original",
                path: "/workform",
                isshow: false,
            }
        ]
    },
    {
        label: "就业升学可视化",
        icon: "el-icon-s-help",
        id: 2,
        children: [
            {
                id: 21,
                label: "就业升学可视化",
                icon: "el-icon-picture-outline",
                path: "/workEcharts",
                isshow: false,
            },
            {
                id: 22,
                label: "学历结构",
                icon: "el-icon-mobile",
                isshow: false,
                path: "/employment"
            },
            {
                id: 23,
                label: "性别占比",
                icon: "el-icon-female",
                isshow: false,
                path: "/sexstract"
            },
            {
                id: 24,
                label: "就业分布",
                isshow: false,
                icon: "el-icon-map-location",
                path: "/map"
            },
            {
                id: 25,
                label: "学院详情",
                isshow: false,
                icon: "el-icon-s-data",
                path: "/college"
            },
            {
                id: 26,
                label: "专业详情",
                isshow: false,
                icon: "el-icon-s-marketing",
                path: "/major"
            },
        ]
    },
    {
        label: "学生论坛",
        id: 3,
        icon: "el-icon-share",
        children: [
            {
                id: 31,
                label: "学生论坛",
                icon: "el-icon-chat-line-square",
                isshow: false,
                path: "/forum"
            }
        ]
    },
    {
        label: "权限管理模块",
        id: 4,
        icon: "el-icon-s-grid",
        children: [
            {
                id: 41,
                label: "分类权限管理",
                icon: "el-icon-position",
                isshow: false,
                path: "/classJur"
            },
            {
                id: 42,
                label: "用户权限管理",
                icon: "el-icon-thumb",
                isshow: false,
                path: "/userJur"
            },
        ]
    },
    {
        label: "管理模块",
        id: 5,
        icon: "el-icon-s-tools",
        isshow: false,
        children: [
            {
                id: 51,
                label: "账号信息管理",
                icon: "el-icon-s-custom",
                isshow: false,
                path: "/account"
            },
            {
                id: 52,
                label: "就业信息上传",
                icon: "el-icon-upload",
                isshow: false,
                path: "/upload"
            },
            {
                id: 53,
                label: "教师资格认证",
                icon: "el-icon-menu",
                isshow: false,
                path: "/authentication"
            },
        ]
    },
]

// 专门用于处理左侧的菜单展示的方法
function HandleMenulist(routerList) {
    for (let i = 0; i < routerList[0].children.length; i++) {
        for (let j = 0; j < menulist.length; j++) {
            for (let k = 0; k < menulist[j].children.length; k++) {
                if (menulist[j].children.length == 0) {
                    break;
                }
                if (
                    "/" + routerList[0].children[i].path ==
                    menulist[j].children[k].path
                ) {
                    menulist[j].children[k].isshow = true;
                }
            }
        }
    }

    // 删除所有不需要展示的二级列表
    for (let i = 0; i < menulist.length; i++) {
        for (let j = menulist[i].children.length - 1; j >= 0; j--) {
            if (menulist[i].children[j].isshow == false) {
                menulist[i].children.splice(j, 1);
            }
        }
    }

    // 通过判断二级列表是否 存在 判断一级列表是否该显示
    // let obj = JSON.parse(JSON.stringify(menulist))

    let obj = menulist.filter(item => {
        return item.children.length > 0
    })

    return obj
}


// 专门用于处理 权限设置页面的数据转换
// 返回数据为 默认选中的 禁用的
function handleJur(routerList) {
    let arr = []   // 默认选中的
    let arr1 = [41, 42, 53]   // admin才能拥有的权限 必须禁用
    for (let i = 0; i < routerList.children.length; i++) {
        for (let j = 0; j < menulist.length; j++) {

            for (let k = 0; k < menulist[j].children.length; k++) {

                if (menulist[j].children.length == 0) {
                    break;
                }
                if (
                    "/" + routerList.children[i].path ==
                    menulist[j].children[k].path
                ) {
                    menulist[j].children[k].isshow = true;
                    arr.push(menulist[j].children[k].id + '')
                }

                for (let h = 0; h < arr1.length; h++) {
                    if (menulist[j].children[k].id == arr1[h]) {
                        menulist[j].children[k].disabled = true
                    }
                }
            }
        }
    }
    // console.log(menulist)
    // console.log(arr)

    return {
        menulist,
        arr
    }
}

// 去除arr中小于10的
function delArr(arr) {
    return arr.filter(item => {
        return item >= 10
    })
}

// 返回一个专门处理 不同身份的用户看昵称的函数
function showName(shengfen, arr) {
    // 用户身份 和全部的参数数组
    if (shengfen == 2) {  //管理员
        return arr
    }
    let arr1 = arr.splice(0, 1)
    return arr

}

// 定义一个处理时间的函数
function moment(date) {
    date = new Date(date);
    var year = date.getFullYear();
    /* 在日期格式中，月份是从0开始的，因此要加0
     * 使用三元表达式在小于10的前面加0，以达到格式统一  如 09:11:05
     * */
    var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
    var day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
    var hours = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
    var minutes = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
    var seconds = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
    // 拼接
    return year + "-" + month + "-" + day + " " + hours + ":" + minutes + ":" + seconds;

}

// 定义一个根据当前路由信息来处理面包削显示参数的函数
function handleTitle(val) {
    // console.log(val)
    // val 当前路由
    for(let i=0;i<menulist.length;i++){
        for(let j=0;j<menulist[i].children.length;j++){
            if(menulist[i].children[j].path==val){
                return {
                    title1:menulist[i].label,
                    title2:menulist[i].children[j].label
                }
            }
        }
    }

}


export {
    moment,
    showName,
    handleJur,
    menulist,
    HandleMenulist,
    delArr,
    handleTitle
}